package com.wlj.security.core.validate.code.sms;

import com.wlj.security.core.properties.WljSecurityProperties;
import com.wlj.security.core.validate.code.ValidateCode;
import com.wlj.security.core.validate.code.ValidateCodeGenerator;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 此bean就不开放给使用者改写了，直接component，不放ValidateCodeBeanConfig里了
 */
@Component("smsValidateCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {


    @Autowired
    private WljSecurityProperties wljSecurityProperties;


    @Override
    public ValidateCode generate(ServletWebRequest request) {
        String code = RandomStringUtils.randomNumeric(wljSecurityProperties.getCode().getSms().getLength());
        return new ValidateCode(code, wljSecurityProperties.getCode().getSms().getExpireIn());
    }


    public WljSecurityProperties getWljSecurityProperties() {
        return wljSecurityProperties;
    }

    public void setWljSecurityProperties(WljSecurityProperties wljSecurityProperties) {
        this.wljSecurityProperties = wljSecurityProperties;
    }
}
